<!DOCTYPE html>
<html  style="background: #fff!important">
<head lang="en">
<meta charset="UTF-8">
<meta name='apple-touch-fullscreen' content='yes'>
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta content="fullscreen=yes,preventMove=no" name="ML-Config">
<meta name="apple-mobile-web-app-status-bar-style" content="black"/>
<meta name="format-detection" content="telephone=no,email=no,address=no"/>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
<title>出货库存</title>
<link rel="stylesheet" href="/style/lh/css/style.css">
<link type="text/css" rel="stylesheet" href="/style/css/sweet-alert.css">
<link rel="stylesheet" type="text/css" href="/style/wei/css/xshop.css?ver=2019041701">
<link rel="stylesheet" href="/style/css/distribution.css">
<script src="/style/wei/js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="/style/lh/js/style.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="/style/js/sweet-alert.min.js"></script>
</head>
<body style="background: #fff!important">
    <!-- 出货库存 -->
    <div class="ship-bg">
        <img src="/style/lh/images/ship1.png">
    </div>
    <div class="ship-content">
        <ul>
            <li>
                <i>商品名称：</i>
                <b><?=$this->data[$this->goods_id];?></b>
            </li>
            <li>
                <i>可用库存：</i>
                <b><?=$this->stock[$this->goods_id] ? : 0;?></b>
            </li>
            <li>
                <i>对方手机：</i>
                <input type="tel" id="mobile" maxlength="11" value="" placeholder="请输入手机号码">
            </li>
            <li>
                <i>对方姓名：</i>
                <b id="name"></b>
            </li>
             <li>
                <i>出货数量：</i>
                <input type="tel" id="number" maxlength="3" value="" placeholder="请输入出货数量">
            </li>
            <li>
                <button>确认出货</button>
            </li>
        </ul>
    </div>
<div class="foot-menu">
<ul class="clearfix">
<a href="/"><li><i class="ico-7"></i><span>首页</span></li></a>
<a href="/index/goodslist"><li><i class="ico-1"></i><span>代理</span></li></a>
<a href="/cart/cart"><li><i class="ico-5"></i><span>购物车</span></li> </a>     
 <a href="/college"><li><i class="ico-8"></i><span>商学院</span></li> </a>       
<a href="/user/index"><li class="on"><i class="ico-4"></i><span>我的</span></li> </a>    
</ul>
</div>
<script type="text/javascript">
var max_stock = <?=$this->stock[$this->goods_id] ? : 0;?>;
$(document).ready(function(e){

    $("button").bind("click",function(){
        _transfer();
    });

    $("#mobile").bind("keyup",function(){
        _guid = 0;
        if($("#mobile").prop("value").length == 11)
        {
            _checkmobile($("#mobile").prop("value"));
        }
    });

});
var _guid = 0;
function _checkmobile(mb)
{
    var par = /^(13|14|15|16|17|18|19)+([0-9]{9})$/;

    if( !par.test(mb))
    {
        swal("手机号码格式错误");
    }
    else
    {
        $.post("/stock/ajax",
        {
            "act":"check",
            "mobile":mb,
            "mr":Math.random()
        },function(json){
            console.log(json);

            if(json.code == 200)
            {
                _guid = json.data['uid'];
                $("#name").html(json.data['name']);
            }
            else
            {
                _guid = 0;
                $("#name").html('');
            }
        },"json");
    }
}

function _transfer()
{
    var stock = parseInt( $("#number").prop("value") );

    if( $("#mobile").prop("value").length < 11)
    {
        swal("请输入手机号码");
    }
    else if(_guid == 0)
    {
        swal("用户不存在或未升级");
    }
    else if( stock == 0 )
    {
        swal("请填写出货数量");
    }
    else if(stock > max_stock)
    {
        swal("可用库存不足");
    }
    else
    {
        $.post("/stock/ajax",
        {
            "act":"transfer",
            "mobile":$("#mobile").prop("value"),
            "uid":_guid,
            "number":stock,
            "goods_id":<?=$this->goods_id;?>,
            "mr":Math.random()
        },function(json){
            console.log(json);

            if(json.code == 200)
            {
               swal("出货成功",false,"success");
               setTimeout(function(){

                window.location.reload();

               },2000);
            }
            else
            {
                swal("出货失败","错误码"+json.code,"error");
            }
        },"json");
    }
}
</script>
</body>
</html>